﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            foreach (RouteConfigEntity current in RouteConfig.RouteConfigs)
            {
                AreaRegistrationContext areaRegistrationContext = new AreaRegistrationContext(current.AreaName, routes);
                areaRegistrationContext.MapRoute(current.Name, current.AreaName + "/{controller}/{action}/{id}", new
                {
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional
                }, null, current.NameSpaces);
            }

            //区域默认路由
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new
                {
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional,
                    NameSpace = "Front.Controllers"
                }
            ).DataTokens.Add("Area", "Front");
        }
        /// <summary>
        /// 可用路由
        /// </summary>
        private static List<RouteConfigEntity> RouteConfigs = new List<RouteConfigEntity>
		{
			new RouteConfigEntity
			{
				Name = "Erp_default",
				AreaName = "ERP",
				NameSpaces = new string[]
				{
					"Erp.Controllers"
				}
            },

            new RouteConfigEntity
			{
				Name = "Front_default",
				AreaName = "Front",
				NameSpaces = new string[]
				{
					"Front.Controllers"
				}
            }
            //这里添加新的路由 
        };
    }

    public class RouteConfigEntity
    {
        public string Name { get; set; }
        public string AreaName { get; set; }
        public string[] NameSpaces { get; set; }
    }
}